package com.jic.manager.controller.manage.merchant;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.manager.entity.MerchantWeBankContractFile;
import com.jic.manager.request.MerchantWeBankContractFileRequest;
import com.jic.manager.request.MerchantWeBankContractRequest;
import com.jic.manager.response.MerchantWeBankContractResponse;
import com.jic.manager.service.MerchantWeBankContractFileService;
import com.jic.manager.service.MerchantWeBankContractService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 商户财务信息控制器
 * @autho mj
 */
@RestController
@RequestMapping("merchantWeBankContract")
@Slf4j
public class MerchantWeBankContractController {

    @Resource
    private MerchantWeBankContractService merchantWeBankContractService;

    @Resource
    private MerchantWeBankContractFileService merchantWeBankContractFileService;


    /**
     * 商户合同列表
     * @param request
     * @return
     */
    @PostMapping("/getContractListByMerchantId")
    @ResponseBody
    @ApiOperation(value = "商户合同列表")
    public RestResult<PageResult<MerchantWeBankContractResponse>> getContractListByMerchantId(@RequestBody MerchantWeBankContractRequest request) {
        try {
            log.debug("getContractListByMerchantId " + request);
            PageResult<MerchantWeBankContractResponse> pageResult = merchantWeBankContractService.queryPage(request, new Page() {{
                setStart(request.getStart());
                setLimit(request.getLimit());
            }});
            return RestResult.success(pageResult);
        }catch (Exception e){
            log.error("Manager getContractListByMerchantId error：",e);
            return RestResult.error("9999","系统异常，商户合同列表查询失败");
        }
    }



    /**
     * 查看商户合同详情
     * @param request
     * @return
     */
    @PostMapping(value = "/getContractInfo")
    public RestResult<MerchantWeBankContractResponse> getContractInfo(@RequestBody MerchantWeBankContractRequest request){
        try {
            log.debug("getContractInfo " + request);
            return RestResult.success(merchantWeBankContractService.getContractInfo(request));
        }catch (Exception e){
            log.error("Manager getContractInfo error：",e);
            return RestResult.error("9999","系统异常，查询合同详情失败");
        }
    }

    /**
     * 新增商户合同信息
     * @param request
     * @return
     */
    @PostMapping(value = "/addContractInfo")
    public RestResult<Long> addContractInfo(@RequestBody MerchantWeBankContractRequest request){
        try {
            log.debug("getMerchantInfo " + request);
            return RestResult.success( merchantWeBankContractService.addContractInfo(request));
        }catch (Exception e){
            log.error("Manager addMerchantFinanceInfo error：",e);
            return RestResult.error("9999","系统异常，新增合同信息失败");
        }
    }

    /**
     * 保存上传数据
     * @param request
     * @return
     */
    @PostMapping(value = "/addContractFile")
    public RestResult<MerchantWeBankContractFile> addContractFile(@RequestBody MerchantWeBankContractFileRequest request){
        try {
            log.debug("addContractFile " + request);
            return RestResult.success( merchantWeBankContractFileService.addContractFile(request));
        }catch (Exception e){
            log.error("Manager addContractFile error：",e);
            return RestResult.error("9999","系统异常，上传失败");
        }
    }

    /**
     * 删除上传数据
     * @param request
     * @return
     */
    @PostMapping(value = "/deleteContractFile")
    public RestResult<Long> deleteContractFile(@RequestBody MerchantWeBankContractFileRequest request){
        try {
            log.debug("deleteContractFile " + request);
            return RestResult.success( merchantWeBankContractFileService.delete(request.getId()));
        }catch (Exception e){
            log.error("Manager deleteContractFile error：",e);
            return RestResult.error("9999","系统异常，删除失败");
        }
    }


}
